package com.ingrid.web.compras.model;

import java.util.ArrayList;

public class Basket {

	private ArrayList<BasketItem> items;

	public Basket() {
		this.items = new ArrayList<>();
	}
	
	public ArrayList<BasketItem> getItems(){
		return this.items;
	}

	public BasketItem findItem(Product product) {
 		for (int i = 0; i < this.items.size(); i++) {
			BasketItem currentItem = this.items.get(i);
			if (currentItem.getProduct().equals(product)) {
				return currentItem;
			}
		}

		BasketItem item = new BasketItem(product);
		this.items.add(item);

		return item;
	}
}
